<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH . 'models/m_select.php';

/**
 * Модель выборки кинопартнерок
 *
 * @package CoreFramework
 * @version 1.0
 * @author Gennadiy Kozlenko
 */
class M_Select_Partners extends M_Select {
   
   /**
    * Конструктор класса
    *
    * @access public
    * @return M_Select_Partners
    */
   function M_Select_Partners() {
      parent::M_Select();
      $this->load->language('select_partners');
      $this->load->helper('element');
      // Устанавливаем запрос
      $sql = "
         SELECT
            p.id_partner AS id,
            p.title,
            p.type,
            COUNT(vp.id_video) AS videos,
            p.shop,
            p.partner_id,
            p.position,
            p.status
         FROM
            " . $this->db->dbprefix('partners') . " p
               LEFT JOIN " . $this->db->dbprefix('video_partners') . " vp ON (vp.id_partner = p.id_partner)
         WHERE
            p.status <> 'deleted'
         GROUP BY
            p.id_partner
      ";
      parent::set_sql($sql);
      parent::add_sort('position');
   } // end M_Select_Partners
   
   /**
    * Установка SQL запроса
    *
    * @access public
    * @param string $table
    */
   function set_sql($sql) {
      
   } // end set_sql
   
   /**
    * Обработка результата
    *
    * @access protected
    * @param array $result
    */
   function _process_result(&$result) {
      $result['position'] = create_text('positions[' . $result['id'] . ']', $result['position'], 'size="2" class="i"');
   } // end _process_result
   
   /**
    * Обработка результатов
    *
    * @access protected
    * @param array $results
    */
   function _process_results(&$results) {
      // Лишаем таблицу возможности какой-ни было сортировки
      foreach ($this->_fields as &$filed) {
         $filed['sort'] = false;
      }
   } // end _process_results
   
}
